#include "../../client/rpc_client.hpp"
#include "../../common/common.hpp"
#include "../../common/dispatcher.hpp"
#include <thread>
#include <chrono>

void callback(const Json::Value& result)
{
    LOG(DEBUGLEVEL, "result: %d", result.asInt());
}

int main()
{
    // 开启服务发现的测试 现在的地址的就是注册中心的地址
    MyRpc::client::RpcClient rpc_client(true, "127.0.0.1", 9091);
    
    // 进行消息发送
    Json::Value params;
    params["num1"] = 11;
    params["num2"] = 22;
    Json::Value result;

    // 同步发送请求
    bool flag = rpc_client.call("Add", params, result);
    if(flag != false)
    {
        LOG(DEBUGLEVEL, "result: %d", result.asInt());
    }

    // 异步消息发送
    MyRpc::client::RpcCaller::AsyncResponse rsp;
    params["num1"] = 44;
    params["num2"] = 55;
    flag = rpc_client.call("Add", params, rsp);
    if(flag != false)
    {
        result = rsp.get();
        LOG(DEBUGLEVEL, "result: %d", result.asInt());
    }
    

    // 函数回调方法发送
    params["num1"] = 66;
    params["num2"] = 77;
    flag = rpc_client.call("Add", params, callback);

    // 等待5秒之后再关闭连接
    std::this_thread::sleep_for(std::chrono::seconds(5));
    return 0;
}
